﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LanhuFx.Services
{
    public class PagerResult<TEntity, T>
    {
        public PagerResult(
            PagerCondition<T> PagerCondition,
            IEnumerable<TEntity> arg_Data,
            bool innerCalculate = true,
            Func<PagerResult<TEntity, T>, List<TEntity>> thenLoadData = null,
            Func<PagerResult<TEntity, T>, object> thenLoadOtherData = null
            )
        {
            if (innerCalculate)
            {
                var data_count = arg_Data.Count();

                PagerCondition.SetDataCount(data_count);

                this.Data = arg_Data.Skip(PagerCondition.Start).Take(PagerCondition.PageSize).ToList();
            }
            else
            {
                this.Data = arg_Data.ToList();
            }

            if (thenLoadData != null)
            {
                this.Data = thenLoadData(this);
            }

            if (thenLoadOtherData != null)
            {
                this.OtherData = thenLoadOtherData(this);
            }

            this.PagerCondition = PagerCondition;
        }

        public PagerResult(
            PagerCondition<T> arg_PagerCondition,
            List<TEntity> arg_Data,
            Object arg_OtherData,
            bool arg_conver)
        {
            PagerCondition = arg_PagerCondition;
            Data = arg_Data;
            OtherData = arg_OtherData;
        }

        public PagerCondition<T> PagerCondition { get; set; }
        public List<TEntity> Data { get; set; }
        public Object OtherData { get; set; }

        public bool Any()
        {
            throw new NotImplementedException();
        }
    }
}
